package com.lab.webSocket.controller;

import com.lab.webSocket.dto.JsonMsgDto;
import com.lab.webSocket.dto.UserDto;
import com.lab.webSocket.service.LoginService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;

/**
 * Created by xu_jiaHui on 2017/8/26.
 */
@Controller
@RequestMapping("/ws_login")
public class LoginController {

    @Resource
    private LoginService loginService;

    @RequestMapping("/loginCheck")
    @ResponseBody//userId其实是现在的Account userPsw其实是现在的userPassword
    public JsonMsgDto loginCheck(String userId,String userPsw)throws Exception{
        System.out.println("userId:"+userId+"userPsw:"+userPsw);
        JsonMsgDto jsonMsgDto=new JsonMsgDto();
        try{
            jsonMsgDto.setSuccess(true);
            jsonMsgDto.setJsonData(loginService.loginCheck(userId,userPsw));
        }catch (Exception e){
            jsonMsgDto.setSuccess(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

    @RequestMapping("/userRegister")
    @ResponseBody
    public JsonMsgDto userRegister(UserDto userDto)throws Exception{
        JsonMsgDto jsonMsgDto=new JsonMsgDto();
        try{
            jsonMsgDto.setSuccess(true);
            jsonMsgDto.setJsonData(loginService.userRegister(userDto));
        }catch (Exception e){
            jsonMsgDto.setSuccess(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

    @RequestMapping("/checkUserId")
    @ResponseBody//userId其实是现在的Account
    public JsonMsgDto checkUserId(String userId)throws Exception{
        JsonMsgDto jsonMsgDto=new JsonMsgDto();
        try{
            jsonMsgDto.setSuccess(true);
            jsonMsgDto.setJsonData(loginService.checkUserId(userId));
        }catch (Exception e){
            jsonMsgDto.setSuccess(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }




}
